@ibiz-template-plugin/ibiz-file-previewer 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -18420,7 +18420,7 @@ const ImagePage = (props) => {
18420
18420
  };
18421
18421
  if (props.state.value.mode === ImageMode.WIDTH) {
18422
18422
  Object.assign(result, {
18423
- width: "".concat(parentStyle.value.width * props.state.value.scale, "px")
18423
+ width: "".concat((parentStyle.value.width - 24 - 6) * props.state.value.scale, "px")
18424
18424
  });
18425
18425
  } else if (props.state.value.mode === ImageMode.PAGE) {
18426
18426
  Object.assign(result, {
@@ -18554,16 +18554,57 @@ const FilePreviewImageGroup = (props) => {
18554
18554
  }
18555
18555
  });
18556
18556
  };
18557
+ let updateIsScrollingTimer;
18557
18558
  const updateIsScrolling = () => {
18558
18559
  isScrolling.value = true;
18559
- setTimeout(() => {
18560
+ if (updateIsScrollingTimer) {
18561
+ clearTimeout(updateIsScrollingTimer);
18562
+ }
18563
+ updateIsScrollingTimer = setTimeout(() => {
18560
18564
  isScrolling.value = false;
18561
18565
  }, 1e3);
18562
18566
  };
18567
+ const MAX_ATTEMPTS = 30;
18568
+ const STABLE_THRESHOLD = 2;
18569
+ let requestAnimationFrameId;
18570
+ const scrollToPageWhenStable = (pageIndex) => {
18571
+ let lastTop = null;
18572
+ let stableCount = 0;
18573
+ let attempt = 0;
18574
+ const tryScroll = () => {
18575
+ const container = contentRef.current;
18576
+ if (!container) return;
18577
+ const pageElement = container.querySelector(
18578
+ '[data-page-index="'.concat(pageIndex, '"]')
18579
+ );
18580
+ if (!pageElement) return;
18581
+ const rect = pageElement.getBoundingClientRect();
18582
+ if (rect.height > 0) {
18583
+ if (lastTop !== null && Math.abs(rect.top - lastTop) < 1) {
18584
+ stableCount++;
18585
+ } else {
18586
+ stableCount = 0;
18587
+ }
18588
+ lastTop = rect.top;
18589
+ if (stableCount >= STABLE_THRESHOLD) {
18590
+ scrollToPage(pageIndex);
18591
+ updateIsScrolling();
18592
+ return;
18593
+ }
18594
+ }
18595
+ attempt++;
18596
+ if (attempt < MAX_ATTEMPTS) {
18597
+ requestAnimationFrameId = requestAnimationFrame(tryScroll);
18598
+ } else {
18599
+ scrollToPage(pageIndex);
18600
+ updateIsScrolling();
18601
+ }
18602
+ };
18603
+ requestAnimationFrameId = requestAnimationFrame(tryScroll);
18604
+ };
18563
18605
  const handlePageClick = (pageIndex) => {
18564
18606
  controller.updateState({ currentPage: pageIndex });
18565
- scrollToPage(pageIndex);
18566
- updateIsScrolling();
18607
+ scrollToPageWhenStable(pageIndex);
18567
18608
  };
18568
18609
  const handleInput = (e2) => {
18569
18610
  const target = e2.target;
@@ -18602,16 +18643,19 @@ const FilePreviewImageGroup = (props) => {
18602
18643
  return () => {
18603
18644
  var _a;
18604
18645
  (_a = contentRef.current) == null ? void 0 : _a.removeEventListener("scroll", handleScroll);
18646
+ if (updateIsScrollingTimer) {
18647
+ clearTimeout(updateIsScrollingTimer);
18648
+ }
18649
+ if (requestAnimationFrameId) {
18650
+ cancelAnimationFrame(requestAnimationFrameId);
18651
+ }
18605
18652
  };
18606
18653
  }, []);
18607
18654
  return /* @__PURE__ */ u("div", { className: "file-preview-image-group", children: [
18608
18655
  /* @__PURE__ */ u(
18609
18656
  "div",
18610
18657
  {
18611
- className: "image-group-left-container",
18612
- style: {
18613
- visibility: state.value.showThumbnailPanel ? "visible" : "hidden"
18614
- },
18658
+ className: "image-group-left-container ".concat(state.value.showThumbnailPanel ? "image-group-left-container--open" : ""),
18615
18659
  children: /* @__PURE__ */ u(
18616
18660
  ThumbnailPanel,
18617
18661
  {